//
//  TouchView.m
//  NumLot
//
//  Created by luotao on 12-8-20.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "TouchView.h"
#import "Cons.h"

@implementation TouchView
@synthesize eventCallback;
@synthesize touchCount;
@synthesize touchBegin;
@synthesize touchMoved;
@synthesize touchEnd;
@synthesize startX;
@synthesize currentX;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Initialization code
    }
	self.userInteractionEnabled=YES;
    return self;
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
	
    UITouch *touch = [[event allTouches] anyObject];	
	if ([touch view] != self) {
		if(LOG_DEBUG){
			NSLog(@"TouchView do something");
		}
		
	}
	if(LOG_DEBUG){
		NSLog(@"touch tag : %d",touch.view.tag);
	}
	
	CGPoint beginPoint = [[touches anyObject] locationInView:self];
	startX = beginPoint.x;
	currentX=beginPoint.x;
	
	if(touchBegin!=nil){
		[((NSObject *)eventCallback) performSelector:touchBegin withObject:touches  withObject:self];
	}
	
}

- (void) touchesMoved:(NSSet *) touches withEvent: (UIEvent *) event
{	
	if(LOG_DEBUG){
		NSLog(@"TouchView touch size : %d",[touches count]);
	}
	if(touchMoved!=nil){
		[((NSObject *)eventCallback) performSelector:touchMoved withObject:touches  withObject:self];
	}
}

- (void) touchesEnded:(NSSet *) touches withEvent: (UIEvent *) event
{
	//	NSLog(@"currentX : %f",currentX);
	//	[vc transOnAnimi:currentX];
	touchCount++;
	if(touchEnd!=nil){
		[((NSObject *)eventCallback) performSelector:touchEnd withObject:touches  withObject:self];
	}
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (void)dealloc {
    [super dealloc];
}


@end
